﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_BidTableProductSelect : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string _Where,_ProjectId;
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCheckProjectComp);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            Db db = new Db();
            DbPage dbPage = new DbPage(db);

            string strGetPageLink = "";

            dbPage.Table = "Product";                                               //表名，可以多个表关联
            dbPage.Key = "ProductId";                                               //该查询可以唯一表示记录的字段，该属性必须设置且只能有一个唯一标识字段
            _ProjectId = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["ProjectId"]));
            _Where = "  productid not in   (select productid from bid_project_product where projectid=" + _ProjectId + ")";
            if (SysFun.ToInt(Request.QueryString["SortId"]) > 0)
            {
                string strSortId = SysFun.IsSQL(SysFun.ToInt(Request.QueryString["SortId"]).ToString()) + "," + SysFun.IsSQL(GetNextSortId(SysFun.ToInt(Request.QueryString["SortId"])));
                dbPage.Where = "SortId In (" + strSortId.Substring(0, strSortId.Length - 1) + ") and " + _Where;
                strGetPageLink = "&SortId=" + SysFun.IsSQL(SysFun.ToInt(Request.QueryString["SortId"]));
            }
            if (SysFun.ToTrim(Request.QueryString["ProductName"]).Length > 0)
            {
                dbPage.Where = "(ProductName Like '%" + SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["ProductName"])) + "%' or SpellingCode Like '%" + SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["ProductName"])) + "%') and " + _Where;
                strGetPageLink = "&ProductName=" + SysFun.IsSQL(Server.UrlEncode(SysFun.ToTrim(Request.QueryString["ProductName"])));
            }
            dbPage.SelectField = "*";                                               //可以不设，默认为“*”

            dbPage.OrderBy = "ProductName,Medicinemodel,Outlookc";                                //排序字段，可以不输入。不输入时以 Key 作为排序字段

            //dbPage.PageIndex = SysFun.ToInt(Request.QueryString["PG"]);             //设置需要查询第几页
            dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);
            dbPage.PageSize = 30;                                                   //设置每页显示多少条记录


            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("<table width='100%' cellspacing='0' cellpadding='3'>");
            sb.Append("<tr style='font-weight:bold'>");
            sb.Append("<td align='center' nowrap>序号</td>");
            sb.Append("<td nowrap>通用名</td>");
            sb.Append("<td align='center' nowrap>剂型</td>");
            sb.Append("<td align='center' nowrap>规格</td>");
            sb.Append("<td align='center' nowrap>转换系数</td>");
            sb.Append("<td align='center' nowrap>单位</td>");
            sb.Append("<td align='center' nowrap>拼音码</td>");
            sb.Append("</tr>");

            int intNum = 0;
            System.Data.IDataReader dr = dbPage.ExecuteReader();
            while (dr.Read())
            {
                intNum++;
                sb.Append("<tr ProductId='" + SysFun.ToInt(dr["ProductId"]) + "' style='behavior:url(BidTableProductSelect.htc)'>");
                sb.Append("<td align='center'>" + ((dbPage.PageIndex - 1) * dbPage.PageSize + intNum) + "</td>");
                sb.Append("<td>" + SysFun.ToTrim(dr["ProductName"]) + "</td>");
                sb.Append("<td align='center'>" + SysFun.ToTrim(dr["Medicinemodel"]) + "</td>");
                sb.Append("<td align='center'>" + SysFun.ToTrim(dr["Outlookc"]) + "</td>");
                sb.Append("<td align='center'>" + SysFun.ToTrim(dr["xishu"]) + "</td>");
                sb.Append("<td align='center'>" + SysFun.ToTrim(dr["Unit"]) + "</td>");
                sb.Append("<td>" + SysFun.ToTrim(dr["SpellingCode"]) + "</td>");
                sb.Append("</tr>");
            }
            dr.Close();

            sb.Append("</table>");

            this.DbPageFlip1.DbPage = dbPage;

            //sb.Append("<p align='right'>" + dbPage.GetPageLink("BidTableProductSelect.aspx?PG={PageNum}" + strGetPageLink) + "</p>");

            //Label lab = new Label();
            Label1.Text = sb.ToString();
            //frmMain.Controls.Add(lab);
            db.Close();
        }
    }

    private string GetNextSortId(int sortId)
    {
        string strSql;
        Db db = new Db();
        System.Data.IDataReader dr;

        string strId = "";

        strSql = "Select SortId From product_sort Where FrontSortId=" + sortId.ToString();
        dr = db.DataReader(strSql);
        while (dr.Read())
        {
            strId += SysFun.ToTrim(dr["SortId"]) + ",";
            strId += GetNextSortId(SysFun.ToInt(dr["SortId"]));
        }
        dr.Close();

        db.Close();

        return strId;
    }
}
